class Book:
    __count = 0  # 类私有属性 → _Book__count
    public_class_attr = "我是公共类属性"

    def __init__(self, name):
        self.__name = name  # 实例私有属性 → _Book__name
        self.public_attr = "我是公共实例属性"
        Book.__count += 1

    def __change_name(self, new_name):  # 私有方法 → _Book__change_name
        self.__name = new_name

    def public_method(self):
        return "我是公共方法"

    def print_info(self):
        print(f'Book name:{self.__name}')

    @classmethod
    def get_count(cls):
        return cls.__count


# 创建实例
books = [Book('红楼梦'), Book('了不起的盖茨比')]

print("=== 完整的属性方法分析 ===")

# 分析实例
instance = books[0]
print(f"\n实例: {instance}")

print("\n[实例属性字典 __dict__]:")
for key, value in instance.__dict__.items():
    print(f"  {key}: {value}")

print("\n[所有可访问的属性和方法 dir()]:")
methods = []
attributes = []
for attr_name in dir(instance):
    attr_value = getattr(instance, attr_name)
    if callable(attr_value):
        methods.append(attr_name)
    else:
        attributes.append(attr_name)

print("  属性:")
for attr in sorted(attributes):
    if not attr.startswith('__') or '_Book__' in attr:
        print(f"    {attr}: {getattr(instance, attr)}")

print("  方法:")
for method in sorted(methods):
    if not method.startswith('__') or '_Book__' in method:
        print(f"    {method}")

print("\n[类的属性字典 Book.__dict__]:")
for key, value in Book.__dict__.items():
    if not key.startswith('__') or key.startswith('_Book__'):
        print(f"  {key}: {value}")

# 验证名称修饰
print("\n=== 名称修饰验证 ===")
print("实际存储的属性名:")
print(f"  __name 被修饰为: _Book__name ")
print(f"  __count 被修饰为: _Book__count ")

# 通过修饰后的名称访问
print("\n通过修饰后的名称访问:")
instance._Book__change_name('石头记')
instance.print_info()